home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / memory & system tools / membar / membar.c < prev    next >
C/C++ Source or Header  |  1996-04-07  |  3KB  |  189 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <exec/execbase.h>
  4. #include <intuition/intuition.h>
  5. #include <time.h>
  6.  
  7. /*************/
  8. /* CONSTANTS */
  9. /*************/
  10.  
  11. #define MAXMODE 2
  12.  
  13. /***********/
  14. /* GLOBALS */
  15. /***********/
  16.  
  17. char WindowTitle[80] = "MemBar";
  18.  
  19. struct NewWindow nw =
  20.     {
  21.     0, 0, 320, 10,
  22.     0, 1,
  23.     MOUSEBUTTONS | CLOSEWINDOW,
  24.     WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH | NOCAREREFRESH | RMBTRAP,
  25.     NULL,
  26.     NULL,
  27.     WindowTitle,
  28.     NULL,
  29.     NULL,
  30.     0, 0, 0, 0,
  31.     WBENCHSCREEN
  32.     };
  33.  
  34. /**************/
  35. /* PROTOTYPES */
  36. /**************/
  37.  
  38. ULONG MaxMem(__D0 ULONG);
  39.  
  40. /********************/
  41. /* main()           */
  42. /********************/
  43.  
  44. void main()
  45.     {
  46.     struct Window *win;
  47.     struct RastPort *rp;
  48.  
  49.     SHORT delay = 20;
  50.     SHORT mode = 0;
  51.     BOOL bool = TRUE;
  52.  
  53.     win = (struct Window *)OpenWindow(&nw);
  54.     if ( !win )
  55.         {
  56.         puts("MemBar : Can't open window.");
  57.         exit(0);
  58.         }
  59.  
  60.     rp = win->RPort;
  61.  
  62.     while ( bool )
  63.         {
  64.         struct IntuiMessage *msg;
  65.  
  66.         Delay(delay);
  67.  
  68.         while ( msg = (struct IntuiMessage *)GetMsg(win->UserPort) )
  69.             {
  70.             ULONG class = msg->Class;
  71.             USHORT code = msg->Code;
  72.  
  73.             ReplyMsg(msg);
  74.  
  75.             switch ( class )
  76.                 {
  77.                 case CLOSEWINDOW :
  78.                     bool = FALSE;
  79.                     break;
  80.                 case MOUSEBUTTONS :
  81.                     if ( code == MENUUP )
  82.                     {
  83.                         mode++;
  84.  
  85.                         if ( mode >= MAXMODE )
  86.                         mode = 0;
  87.                     }
  88.                     break;
  89.                 }
  90.             }
  91.  
  92.         switch ( mode )
  93.             {
  94.             case 0 :
  95.                 {
  96.                 /***************/
  97.                 /* show membar */
  98.                 /***************/
  99.  
  100.                 ULONG max;
  101.                 LONG x;
  102.  
  103.                 SetAPen(rp, 2);
  104.                 Move(rp, 32, 1); Draw(rp, 30, 8);
  105.                 Move(rp, 31, 1); Draw(rp, 31, 8);
  106.                 Move(rp, 264, 1); Draw(rp, 264, 8);
  107.                 Move(rp, 263, 1); Draw(rp, 263, 8);
  108.                 Move(rp, 32, 1); Draw(rp, 262, 1);
  109.                 Move(rp, 32, 4); Draw(rp, 262, 4);
  110.                 Move(rp, 32, 5); Draw(rp, 262, 5);
  111.                 Move(rp, 32, 8); Draw(rp, 262, 8);
  112.  
  113.                 max = MaxMem(MEMF_CHIP);
  114.  
  115.                 x = 231 * (max - AvailMem(MEMF_CHIP)) / max + 32;
  116.  
  117.                 SetAPen(rp, 3);
  118.                 Move(rp, 32, 2); Draw(rp, x, 2);
  119.                 Move(rp, 32, 3); Draw(rp, x, 3);
  120.  
  121.                 x++;
  122.  
  123.                 SetAPen(rp, 2);
  124.                 Move(rp, 263, 2); Draw(rp, x, 2);
  125.                 Move(rp, 263, 3); Draw(rp, x, 3);
  126.  
  127.                 max = MaxMem(MEMF_FAST);
  128.                 x = 231 * (max - AvailMem(MEMF_FAST)) / max + 32;
  129.  
  130.                 SetAPen(rp, 3);
  131.                 Move(rp, 32, 6); Draw(rp, x, 6);
  132.                 Move(rp, 32, 7); Draw(rp, x, 7);
  133.  
  134.                 x++;
  135.  
  136.                 SetAPen(rp, 6);
  137.                 Move(rp, 263, 6); Draw(rp, x, 6);
  138.                 Move(rp, 263, 7); Draw(rp, x, 7);
  139.  
  140.                 delay = 20;
  141.                 }
  142.                 break;
  143.             case 1 :
  144.                 {
  145.                 /*************/
  146.                 /* show time */
  147.                 /*************/
  148.  
  149.                 time_t t = time(NULL);
  150.                 struct tm *tp = localtime(&t);
  151.  
  152.                 if ( (tp->tm_sec == 0) || (delay != 30) )
  153.                     {
  154.                     strftime(WindowTitle, 80, "%a, %d. %b %Y  %H:%M", tp);
  155.                     SetWindowTitles(win, WindowTitle, NULL);
  156.                     }
  157.  
  158.                 delay = 30;
  159.                 }
  160.                 break;
  161.             }
  162.         }
  163.  
  164.     CloseWindow(win);
  165.     exit(0);
  166.     }
  167.  
  168. /********************/
  169. /* MaxMem()         */
  170. /********************/
  171.  
  172. ULONG MaxMem(__D0 ULONG MemType)
  173.     {
  174.     ULONG BlockSize = 0;
  175.     struct MemHeader *MemHeader;
  176.     extern struct ExecBase *SysBase;
  177.  
  178.     Forbid();
  179.  
  180.     for ( MemHeader = (struct MemHeader *)SysBase->MemList.lh_Head ; MemHeader->mh_Node.ln_Succ ; MemHeader = (struct MemHeader *)MemHeader->mh_Node.ln_Succ )
  181.         if ( MemHeader->mh_Attributes & MemType)
  182.         BlockSize += (ULONG)MemHeader->mh_Upper - (ULONG)MemHeader->mh_Lower;
  183.  
  184.     Permit();
  185.  
  186.     return(BlockSize);
  187.     }
  188.  
  189.